package com.hopu.oa.service.impl.daymanage;

import com.hopu.oa.dao.daymanage.DayManageDao;
import com.hopu.oa.entity.daymanage.AoaScheduleList;
import com.hopu.oa.entity.user.AoaUser;
import com.hopu.oa.service.daymanage.DayManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author CC
 */
@Service
public class DayManageServiceImpl implements DayManageService {

    @Autowired
    private DayManageDao dayManageDao;

    @Override
    @Transactional
    public void insert(AoaScheduleList aoaScheduleList, String a) {
        aoaScheduleList.setIsreminded(0);
        dayManageDao.insert(aoaScheduleList);
        Integer rcId = aoaScheduleList.getRcId();
        String[] split = a.split(";");
        for (String s : split) {
            if (!s.equals("") && s != null) {
                AoaUser aoaUser = dayManageDao.selectName(s);
                Integer userId = aoaUser.getUserId();
                dayManageDao.insertASU(rcId, userId);
            }
        }
    }

    @Override
    @Transactional
    public void update(AoaScheduleList aoaScheduleList, Integer rcid, String a) {
        dayManageDao.updateById(aoaScheduleList);
        dayManageDao.deleteASU(rcid);
        String[] split = a.split(";");
        for (String s : split) {
            if (!s.equals("") && s != null) {
                AoaUser aoaUser = dayManageDao.selectName(s);
                Integer userId = aoaUser.getUserId();
                dayManageDao.insertASU(rcid, userId);
            }
        }
    }

    @Override
    public List<AoaScheduleList> selectAll(Integer id, String str, Integer page, Integer size) {
        return dayManageDao.selectAll(id, str, page, size);
    }


}
